package com.cxx.purchasecharge.core.crypto;

/**
 * This interface defines the methods that the Crypto Implementations must implement.
 * 
 */
public interface ICrypto
{

    /**
     * Encrypt the data with automatically generated Initialization Vector.
     * The returned data is converted to a HexString.
     * @param data
     * @return the encrypted data as a hex string
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if the data parameter is null
     */
    public String encrypt(String data) throws CryptoException;
    
    /**
     * Decrypts the specified data which was encrypted using the "encrypt(String)" method.
     * {@link #encrypt(String)}. 
     * 
     * @param encryptedData
     * @return A decrypted string
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if the encryptedData parameter is null
     */
    public String decrypt(String encryptedData) throws CryptoException;
    
    /**
     * Encrypt the data with automatically generated Initialization Vector.
     * 
     * @param data
     *            The data to be encrypted.
     * @return The encrypted data.
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if the data parameter is null
     */
    public byte[] encrypt(byte[] data) throws CryptoException;
    
    /**
     * Decrypts the provided data which was encrypted using one of the "encrypt"
     * methods.
     * {@link #encrypt(byte[])}.
     * 
     * @param encryptedData
     *            The encrypted data.
     * @return The original data before encryption.
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if the encryptedData parameter is null
     */
    public byte[] decrypt(byte[] encryptedData) throws CryptoException;
    
    
    /**
     * Encrypt an object. The method uses java serialization to convert the
     * provided object into an array of bytes, which are then encrypted.
     * 
     * @param obj
     *            The object to be encrypted.
     * @return The encrypted bytes.
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if obj is null
     */
    public byte[] encryptObject(Object obj) throws CryptoException;
    
    /**
     * Decrypt data to an object. Decrypts an object which was encrypted using
     * {@link #encryptObject(Object)}.
     * 
     * @param data
     *            The encrypted data.
     * @return The original object which has been encrypted.
     * @throws CryptoException
     *             if the encryption fails for any reason.
     * @throws IllegalArgumentException
     *             if data is null
     */
    public Object decryptObject(byte[] data) throws CryptoException;
}
